<template>
  <el-container>
    <el-header>
      <el-row>
        <el-col :span="3" class="col-img">
          <div class="login-img">
            <img src="../../../public/login.png" alt="" />
          </div>
        </el-col>
        <el-col :span="18">
          <div>商城后台管理系统</div>
        </el-col>
        <el-col :span="3">
          <el-button @click="loginOut">退出</el-button>
        </el-col>
      </el-row>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '60px' : '200px'">
        <div class="aside-ss" @click="isCollapse = !isCollapse">||||</div>
        <el-menu
          :collapse="isCollapse"
          :unique-opened="true"
          :collapse-transition="false"
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="rgb(51, 55, 68)"
          text-color="#fff"
          active-text-color="rgb(102, 204, 255)"
          router=""
        >
          <el-submenu
            :index="item1.id + ''"
            v-for="item1 in menus"
            :key="item1.id"
          >
            <template slot="title">
              <i class="el-icon-user"></i>
              <span>{{ item1.authName }}</span>
            </template> 
            <el-menu-item
              :index="'/' + item2.path"
              v-for="item2 in item1.children"
              :key="item2.id"
            >
              <i class="el-icon-s-operation"></i>
              <span>{{ item2.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main style="background:#eaedf1">
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { getMenuApi } from "@/http/api";
export default {
  data() {
    return {
      isCollapse: false,
      menus: [],
    };
  },
  created() {
    // 获取权限菜单
    this.getMenus();
  },
  methods: {
    // 获取权限菜单方法
    async getMenus() {
      let res = await getMenuApi();
      this.menus = res;
    },
    loginOut() {
      // 清除本地登录页
      sessionStorage.removeItem("token");
      // 跳转岛登陆页
      this.$router.push("/login");
    }
  },
  // 退出
};
</script>
<style lang="scss" scoped>
.el-container {
  width: 100%;
  height: 100%;
}
.el-header {
  background-color: #666;
}
.el-aside {
  background: #333744;
  cursor: pointer;
}
.el-row {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 60px;
  color: white;
  font-size: 18px;
  text-align: center;
}
.login-img {
  img {
    width: 50px;
    height: 50px;
  }
}
.col-img {
  padding-right: 20px;
}
.aside-ss {
  background: #999;
  text-align: center;
  height: 30px;
  line-height: 30px;
}
.el-menu {
  border-right: none;
}
</style>
